#ifndef __UnicastUdpSocket_h__
#define __UnicastUdpSocket_h__

#include <base/types.h>
#include "IpSocket.h"

#include <string>

namespace Greatewall
{
    namespace Network
    {
        class UnicastUdpSocket : public IpSocket
        {
        public:
            enum UnicastMode
            {
                SERVER,
                CLIENT,
                PEER
            };
            UnicastUdpSocket(SocketEventMonitor& monitor, SysSockHandler hdl = -1)
                : IpSocket(monitor, hdl)
            {}

            virtual ~UnicastUdpSocket()
            {}

            virtual void
            handleInbound() = 0;

            virtual bool
            handleOutbound() = 0;

            virtual bool
            send(const char* buf, ssize_t& size, bool non_block = true);

            virtual bool
            recv(char*& buf, ssize_t& size, bool non_block = true);

            bool
            sendTo(const char* buf, ssize_t& size, std::string& host, int port, bool non_block = true);

            bool
            recvFrom(char*& buf, ssize_t& size, std::string& host, int& port, bool non_block = true);

            static SysSockHandler
            createUniUdpSock();

            bool
            initUniUdpSock(std::string& host, short port, UnicastMode mode, std::string netif="");

            virtual void
            close();

        private:
            std::string _host;
            short       _port;
            UnicastMode _mode;
            std::string _netif;
        };
    }
}
#endif
